#include<bits/stdc++.h>
using namespace std;
int T,n,m,l,k,d[100009],v[100009],a[100009],b[1000009],h[1000005],t[100009];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        memset(b,-1,sizeof(b));
        memset(h,0,sizeof(h));
        scanf("%d%d%d%d",&n,&m,&l,&k);
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&d[i],&v[i],&a[i]);
        }for(int i=1;i<=m;i++){
            scanf("%d",&t[i]);
            b[t[i]]=t[i];
        }for(int i=l;i>=0;i--){
            if(b[i]==-1){
                b[i]=b[i+1];
            }
        }int sum=0,ans=0;
        for(int i=1;i<=n;i++){
            if(v[i]>k&&b[d[i]]!=-1){
                sum++;
                h[b[d[i]]]++;
            }
        }ans=m;
        if(sum)ans--;
        printf("%d %d\n",sum,ans);
    }return 0;
}
